package javagame;

import gameobjects.Igrac;
import gameobjects.Igrac2;

import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class Play extends BasicGameState {
	
	//NABROJIVI TIPOVI
	
	public enum gender {MALE, FEMALE};
	public enum difficulty {EASY, NORMAL, HARD};
	public enum game_mode {MOD1, MOD2};
	public enum play_select {PLAYER1, PLAYER2};
	
	private Image slika;
	private Image male;
	private Image female;
	private Image easy;
	private Image normal;
	private Image hard;
	private Image player1;
	private Image player2;
	private Image survivor;
	private int slikaX;
	private int slikaY;
	private gender pol;
	private difficulty tezina;
	private game_mode mod;
	private play_select brojIgraca;
	private boolean dvaIgraca;
	
	
	private int mouseX, mouseY;
	
	public Play (int state) {}

	public int getID() {
		return 1;
	}

	public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
		slikaX = 0;
		slikaY = 0;
		slika = new Image("res/play.png");
		male = new Image("res/male.png");
		female = new Image("res/female.png");
		easy = new Image("res/easy.png");
		normal = new Image("res/normal.png");
		hard = new Image("res/hard.png");
		player1 = new Image("res/1player.png");
		player2 = new Image("res/2player.png");
		survivor = new Image("res/survivor.png");
		pol = gender.MALE;
		tezina = difficulty.EASY;
		mod = game_mode.MOD1;
		brojIgraca = play_select.PLAYER1;
		dvaIgraca = false;
		Nivo.setPresaoIgru(false);
	}

	public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
		//pozadina
		g.drawImage(slika, slikaX, slikaY);
		
		//gender
		if (pol == gender.MALE) g.drawImage(male, 582, 185);
		else g.drawImage(female, 582, 185);
		
		//difficulty
		if (tezina == difficulty.EASY) g.drawImage(easy, 582, 245);
		else if (tezina == difficulty.NORMAL) g.drawImage(normal, 582, 245);
		else g.drawImage(hard, 582, 245);
		
		//play select
		if (brojIgraca == play_select.PLAYER1) g.drawImage(player1, 582, 305);
		else g.drawImage(player2, 582, 305);
		
		//survivor
		if (Nivo.isPresaoIgru()) survivor.draw(312, 483);
		
	}
	
	public void fullScreenOnOff (GameContainer gc) throws SlickException {
		if (gc.getInput().isKeyDown(Input.KEY_F)) {
			if (gc.isFullscreen()) {
				gc.setFullscreen(false);
			}
			else {
				gc.setFullscreen(true);
			}
		}
	}

	public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
		Input input = gc.getInput();
		mouseX = input.getMouseX();
	  	mouseY = input.getMouseY();
		
	  	fullScreenOnOff(gc);
		
	  	//play adventure
		if ((mouseX >= 312 && mouseX <= 712) && (mouseY >= 367 && mouseY <= 467)) {
			if (input.isMouseButtonDown(0)) {
				// postavlja pol
				if(pol == gender.MALE) Igrac.dohvIgraca().postaviPol(true);
				else Igrac.dohvIgraca().postaviPol(false);
				Igrac.dohvIgraca().ozivi();
				if (dvaIgraca){
					Igrac2.dohvIgraca().setAnimation();
					Igrac2.dohvIgraca().ozivi();
				}
				// postavlja difficulty
				Nivo.setTezina(tezina);
				//postavlja mod
				mod = game_mode.MOD1;
				Nivo.setMod(mod);
				// postavlja dva igraca
				Nivo.setDvaIgraca(dvaIgraca);
				
				Nivo.resetLevel();
				sbg.enterState(5);
			}
		}
		
		//play survivor
		if (Nivo.isPresaoIgru() && (mouseX >= 312 && mouseX <= 712) && (mouseY >= 483 && mouseY <= 583)) {
			if (input.isMouseButtonDown(0)) {
				// postavlja pol
				if(pol == gender.MALE) Igrac.dohvIgraca().postaviPol(true);
				else Igrac.dohvIgraca().postaviPol(false);
				Igrac.dohvIgraca().ozivi();
				if (dvaIgraca){
					Igrac2.dohvIgraca().setAnimation();
					Igrac2.dohvIgraca().ozivi();
				}
				// postavlja difficulty
				Nivo.setTezina(tezina);
				//postavlja mod
				mod = game_mode.MOD1;
				Nivo.setMod(mod);
				// postavlja dva igraca
				Nivo.setDvaIgraca(dvaIgraca);
				
				Nivo.resetLevel();
				sbg.enterState(18);
			}
		}
		
		//play thread demo
		if ((mouseX >= 312 && mouseX <= 712) && (mouseY >= 599 && mouseY <= 699)) {
			if (input.isMouseButtonDown(0)) {
				// postavlja pol
				if(pol == gender.MALE) Igrac.dohvIgraca().postaviPol(true);
				else Igrac.dohvIgraca().postaviPol(false);
				Igrac.dohvIgraca().ozivi();
				if (dvaIgraca){
					Igrac2.dohvIgraca().setAnimation();
					Igrac2.dohvIgraca().ozivi();
				}
				// postavlja difficulty
				Nivo.setTezina(tezina);
				mod = game_mode.MOD2;
				Nivo.setMod(mod);
				// postavlja dva igraca
				Nivo.setDvaIgraca(dvaIgraca);
				
				Nivo.resetLevel();
				sbg.enterState(17);
			}
		}
		
		//gender
		if ((mouseX >= 184 && mouseX <= 561) && (mouseY >= 185 && mouseY <= 235)) {
			if (input.isMousePressed(0)) {
				if(pol == gender.MALE) pol=gender.FEMALE;
				else pol=gender.MALE;
			}
		}
		
		//difficulty
		if ((mouseX >= 184 && mouseX <= 561) && (mouseY >= 245 && mouseY <= 295)) {
			if (input.isMousePressed(0)) {
				if (tezina == difficulty.EASY) tezina=difficulty.NORMAL;
				else if (tezina == difficulty.NORMAL) tezina=difficulty.HARD;
				else tezina=difficulty.EASY;
			}
		}
		
		//game select
		if ((mouseX >= 184 && mouseX <= 561) && (mouseY >= 305 && mouseY <= 355)) {
			if (input.isMousePressed(0)) {
				if(brojIgraca == play_select.PLAYER1) {
					brojIgraca=play_select.PLAYER2;
					dvaIgraca = true;
				}
				else {
					brojIgraca=play_select.PLAYER1;
					dvaIgraca = false;
				}
			}
		}
	
	}
	
}
